home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / c / filebuff.c < prev    next >
C/C++ Source or Header  |  1992-07-13  |  1KB  |  69 lines

  1. #include <dos.h>
  2.  
  3. #define unint unsigned int
  4. #define uchar unsigned char
  5.  
  6. #define TESTING
  7.  
  8. /*
  9.  FILES and BUFFERS are free functions.  Use them without restriction anywhere.
  10.  
  11.     Author: Ben Morris
  12.     Date  : July 2nd, 1992.
  13.  
  14.  */
  15.  
  16. /*
  17.  Code to count number of FILES as set in config.sys.
  18.  */
  19.  
  20. int FILES( void )
  21. {
  22.     union REGS regs;
  23.     struct SREGS sregs;
  24.     unint far *ptr;
  25.     int numfiles = 0;
  26.  
  27.     regs.h.ah = 0x52;
  28.     intdosx( ®s, ®s, &sregs );
  29.  
  30.     ptr = (unint far *) MK_FP( sregs.es, regs.x.bx+0x04 );
  31.     ptr = (unint far *) MK_FP( ptr[1], ptr[0] );
  32.  
  33.     while( FP_OFF( ptr ) != 0xFFFF )
  34.     {
  35.         numfiles += ptr[2];
  36.         ptr = (unsigned int far *) MK_FP( ptr[1], ptr[0] );
  37.     }
  38.  
  39.     return numfiles;
  40. }
  41.  
  42. /*
  43.  Code to count number of BUFFERS as set in CONFIG.SYS.
  44.  */
  45.  
  46. int BUFFERS( void )
  47. {
  48.     uchar far *ptr;
  49.     struct REGPACK regs;
  50.     int numbuffers = 0;
  51.  
  52.     regs.r_ax = 0x5200;
  53.  
  54.     intr( 0x21, ®s );
  55.     ptr = (uchar far *) MK_FP( regs.r_es, regs.r_bx );
  56.  
  57.     numbuffers = *(ptr+0x3F);
  58.  
  59.     return numbuffers;
  60. }
  61.  
  62. #ifdef TESTING
  63. void main( void )
  64. {
  65.     printf( "FILES=%d\n", FILES() );
  66.     printf( "BUFFERS=%d\n", BUFFERS() );
  67. }
  68. #endif
  69.